import { get, post, put, del } from "@/request";

export interface IScheSetting {
  settingId?: number | string | null;
  settingName: string;
  periodicContent: string; // Changed from object to string since API returns stringified JSON
  deptId?: number | string | null;
  status: number; // 0-禁用,1-正常
  createTime?: string;
  updateTime?: string;
}

interface IPaginationResponse<T> {
  content: T[];
  totalElements: number;
}

interface IListParams {
  settingName?: string;
  deptId: number | string;
  status: number;
  page: number;
  size: number;
}

// 获取排班设置列表(分页功能)
export const fetchScheSettings = (params: IListParams) => {
  return get<{ data: IPaginationResponse<IScheSetting> }>(
    `/schedule/scheSetting/${params.deptId}/${params.status}/${params.size}/${params.page}`
  );
};

// 新增排班设置
export const createScheSetting = (data: IScheSetting) => {
  return post("/schedule/scheSetting/addScheSetting", data);
};

// 更新排班设置
export const updateScheSetting = (data: IScheSetting) => {
  return put("/schedule/scheSetting/updateScheSetting", data);
};

// 删除排班设置
export const deleteScheSetting = (settingId: number | string) => {
  return del(`/schedule/scheSetting/${settingId}`);
};

// 查询所有排班设置
export const fetchAllScheSettings = (deptId: number | string) => {
  return get<{ data: IScheSetting[] }>(`/schedule/scheSetting/${deptId}`);
};